package com.zephyr.vchcenter.bpm.decision;

import org.apache.log4j.Logger;

import com.hiaward.bpm.context.ServiceContext;
import com.hiaward.bpm.exception.ParameterException;
import com.hiaward.bpm.exception.RuleException;
import com.hiaward.bpm.exception.ServiceException;
import com.hiaward.bpm.rule.Decision;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.helper.SpringHelper;

public class AuditVerifyDecisionAfterTallyHandler extends Decision {
	private final Logger log=Logger.getLogger(AuditVerifyDecisionAfterTallyHandler.class);
	@Override
	public void exceptionHandle(ServiceContext arg0) {
		

	}

	@Override
	public String make(ServiceContext arg0) throws RuleException,
			ServiceException, ParameterException {
		String vchsid=(String)arg0.getInputParameterValue("vchsid");
		IBaseDao dao = (IBaseDao) SpringHelper.getBean("baseDao");
		Voucher voucher=(Voucher)dao.findById("Voucher", vchsid);
		String acctype=voucher.getAcctype();
		String chkstate=voucher.getChkstate();
		String chkres=voucher.getChkres();
		String transition=null;
		if("1".equals(chkstate)){
			if("2".equals(acctype)){
				voucher.setChkstate("5");
				transition="to financialAfterTally";
				
			}else{
				voucher.setChkstate("1");
			    transition="to auditAfterTally";
			}
		}
		if("4".equals(chkstate)){
			if("2".equals(chkres)){
				voucher.setTallytype("1");
				transition="to tally";
				
			}else{
				voucher.setTallytype("2");
				transition="to refuse";
			}
		}
		dao.saveOrUpdate(voucher);
		return transition;
	}

}
